package NetWork;

import java.io.IOException;
import java.util.HashMap;

/**
 * Created with IntelliJ IDEA.
 * Description:字典服务服务器
 * User:Lenovo
 * Date:2022-04-10
 * Time:10:07
 */
public class TcpDictServer extends TcpThreadPoolEchoServer{
    private HashMap<String,String> dict = new HashMap<>();
    public TcpDictServer(int post) throws IOException {
        super(post);
        //简单构造几个词
        dict.put("cat","猫咪");
        dict.put("dog","狗狗");
        dict.put("bird","小鸟");
        dict.put("frog","青蛙");
        dict.put("sun","太阳");
        dict.put("moon","月亮");
        dict.put("fuck","我草");
    }

    @Override
    public String process(String request) {
        String ret = null;
        if (dict.get(request) == null){
            ret = "该词无法查询~";
        }else {
            ret = dict.get(request);
        }
        return ret;
    }

    public static void main(String[] args) throws IOException {
        TcpDictServer tcpDictServer = new TcpDictServer(9090);
        tcpDictServer.start();
    }
}
